using System;
using System.Linq.Expressions;
using MvvmUtils.Common.Expressions;

namespace MvvmUtils.ViewModels
{
    public static class ViewModelExtensions
    {
        public static ComputedProperty<TViewModel, TProperty> Computed<TViewModel, TProperty>(
            this TViewModel ownerViewModel,
            Expression<Func<TViewModel, TProperty>> propertySelector, 
            Expression<Func<TViewModel, TProperty>> valueComputer) 
            where TViewModel : ViewModel
        {
            var propertyName = propertySelector.GetPropertyName();
            
            return new ComputedProperty<TViewModel, TProperty>(
                propertyName, valueComputer, ownerViewModel);
        }
    }
}